<!--
 * @Description: 列表组件，用于首页、全部景点页面的景点列表
 -->
<template>
  <div id="myList" class="myList">
    <ul>
      <li v-for="item in list" :key="item.product_id">
        <el-popover placement="top">
          <p>确定删除吗？</p>
          <div style="text-align: right; margin: 10px 0 0">
            <el-button
              type="primary"
              size="mini"
              @click="deleteCollect(item.pid)"
              >确定</el-button
            >
          </div>
          <i
            class="el-icon-close delete"
            slot="reference"
            v-show="isDelete"
          ></i>
        </el-popover>
        <router-link
          :to="{ path: '/gl/details', query: { productID: item.pid } }"
        >
          <img src="http://localhost:3000/_nuxt/assets/imgs/placeholder.jpg" alt="" />
          <h2>{{ item.goodName }}</h2>
          <h3>{{ item.des }}</h3>
          <!-- <p>
            <span>{{ item.price }}元</span>
            <span v-show="item.price != item.realPrice" class="del"
              >{{ item.price }}元</span
            >
          </p> -->
        </router-link>
      </li>
      <li>
        <el-pagination
          :page-size="20"
          :pager-count="11"
          layout="prev, pager, next"
          :total="1000"
        >
        </el-pagination>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "MyGl",
  // list为父组件传过来的商品列表
  // isMore为是否显示“浏览更多”
  props: ["list", "isMore", "isDelete"],
  data() {
    return {};
  },
  computed: {
    // 通过list获取当前显示的商品的分类ID，用于“浏览更多”链接的参数
    categoryID: function () {
      let categoryID = [];
      if (this.list != "") {
        for (let i = 0; i < this.list.length; i++) {
          const id = this.list[i].category_id;
          if (!categoryID.includes(id)) {
            categoryID.push(id);
          }
        }
      }
      return categoryID;
    },
  },
  methods: {
    deleteCollect(product_id) {
      const params = new URLSearchParams();
      params.append("productPid", product_id);
      // 获取收藏数据
      this.$axios
        .post("/gd/usercollect/deleteCollect", params, {
          headers: { "content-type": "application/x-www-form-urlencoded" },
        })
        .then((res) => {
          switch (res.data.code) {
            case 200:
              // 删除成功
              // 删除删除列表中的该商品信息
              for (let i = 0; i < this.list.length; i++) {
                const temp = this.list[i];
                if (temp.pid == product_id) {
                  this.list.splice(i, 1);
                }
              }
              // 提示删除成功信息
              // this.notifySucceed(res.data.msg);
              break;
            default:
              // 提示删除失败信息
              // this.notifyError(res.data.msg);
          }
        })
        .catch((err) => {
          return Promise.reject(err);
        });
    },
  },
};
</script>
<style scoped>
.myList ul li {
  z-index: 1;
  float: left;
  width: 1000px;
  height: 180px;
  padding: 10px 0;
  margin: 0 0 14.5px 13.7px;
  background-color: white;
  -webkit-transition: all 0.2s linear;
  transition: all 0.2s linear;
  position: relative;
}
.myList ul li:hover {
  z-index: 2;
  -webkit-box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
  -webkit-transform: translate3d(0, -2px, 0);
  transform: translate3d(0, -2px, 0);
}
.myList ul li img {
  display: block;
  float: left;
  margin-left: 20px;
  margin-top: 10px;
  margin-right: 20px;
  width: 300px;
  height: 150px;
  background: url(../assets/imgs/placeholder.jpg) no-repeat scroll bottom center;
}
/* 标题 */
.myList ul li h2 {
  margin: 25px 10px 0;
  font-size: 25px;
  font-weight: 400;
  color: rgb(0, 0, 0);
  /* text-align: center; */
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.myList ul li h3 {
  margin: 5px 10px;
  height: 18px;
  width: 900px; /* 必须定义宽度 */
  font-size: 14px;
  font-weight: 400;
  color: #b0b0b0;
  text-align: left;
  text-overflow: ellipsis;
  /* overflow: hidden; */
  word-break: break-word; /* 文本行的任意字内断开 */
}
.myList #more {
  text-align: center;
  line-height: 280px;
}
.myList #more a {
  font-size: 18px;
  color: #333;
}
.myList #more a:hover {
  color: #ff6700;
}
.myList ul li .delete {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
}
.myList ul li:hover .delete {
  display: block;
}
.myList ul li .delete:hover {
  color: #ff6700;
}
</style>
